package com.lenovo.lcdm.dcm.controller;

import com.lenovo.lcdm.common.model.ResponseVo;
import com.lenovo.lcdm.team.dto.OperationAuthorityDto;
import com.lenovo.lcdm.team.service.ITeamGroupService;
import com.lenovo.lcdm.team.service.ITeamUserService;
import com.lenovo.lcdm.team.vo.GroupVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther xujing30
 * @Date 2024/03/14
 * @Description
 */
@Slf4j
@RestController
public class ApiController {

    @Autowired
    private ITeamGroupService groupService;

    @Autowired
    private ITeamUserService userService;

    @GetMapping("/v1.0/api/group/list")
    public ResponseVo<List<GroupVo>> getGroupsByName(@RequestParam(required = false, name = "name") String name) {
        ResponseVo<List<GroupVo>> responseVo = new ResponseVo<>();
        List<GroupVo> data = groupService.getGroupByName(name);
        responseVo.setData(data);
        return responseVo;
    }

    @GetMapping("/v1.0/api/user/group")
    public ResponseVo<List<GroupVo>> getGroupsByItCode(@RequestParam(name = "itcode") String itcode) {
        ResponseVo<List<GroupVo>> responseVo = new ResponseVo<>();
        responseVo.setData(userService.getUserGroups(itcode));
        return responseVo;
    }

    @PostMapping("/v1.0/api/operationAuthority")
    public ResponseVo<Object> operationAuthority(@RequestBody OperationAuthorityDto operationAuthorityDto) {
        groupService.operationAuthority(operationAuthorityDto);
        return ResponseVo.success();
    }

}
